var backUrl = {
	addCookie : function(str) {
//		if (null != str) {
//			if (str == "noLogin") {
//				$.cookie("backUrl", window.location.href);
//				window.location.href = global_parameter.login_page;
//			} else if (str == "noPermission") {
//				errorAlert("您没有该操作的权限！");
//			}
//		} else {
//			$.cookie("backUrl", window.location.href);
//			window.parent.location.href = global_parameter.login_page;
//		}
	}
};
var errorAlert = function(msg) {
	art.dialog.alert("<font color='red'><strong>" + msg + "</strong></font>");
};
var tipsAlert = function(msg) {
	art.dialog.tips("<font color='blue'><strong>" + msg + "</strong></font>");
};
// *************************************************************左侧类别展示
/**
 * 加载项目储备类别
 */
var storeOnload = {
	firstCategory : function() {
		$.ajax({
			dataType : "json",
			type : "post",
			async : false,
			url : "/app/category!getAllCategory",
			success : function(data) {
				backUrl.addCookie(data.state);
				if (data.state = "success") {
					storeOnload.createContent(data.msg);
				} else if (data.state == "error") {
					errorAlert(data.msg);
				}
			}
		});
	},
	createContent : function(data) {
		var store = $("#store");
		store.empty();
		var content = "";
		if (data != null && data.length != 0) {
			var intFc = 0, intSc = 0, intTc = 0;
			for ( var int1 = 0; int1 < data.length; int1++) {// 一级
				var firstCss = "";// 一级分类加减样式
				var secondUl = "";// 二级分类内容
				var fc = data[int1];
				if (fc.secondCategories != null && fc.secondCategories.length > 0) {
					firstCss = "class='jia'";
					secondUl += "<ul id='second" + int1
							+ "' class='sz_nav_left_sj' style='margin-left:15px;display:none;'>";

					var secondCategory = fc.secondCategories;
					for ( var int2 = 0; int2 < secondCategory.length; int2++) {// 二级
						var thirdUl = "";// 三级分类内容
						var secondCss = "";// 二级分类加减样式

						var sc = secondCategory[int2];
						if (sc.thirdCategories != null && sc.thirdCategories.length > 0) {
							secondCss = "class='jia'";
							thirdUl += "<ul id='third" + intSc
									+ "' class='sz_nav_left_sj' style='margin-left:15px;display:none;'>";
							var thirdCategory = sc.thirdCategories;
							for ( var int3 = 0; int3 < thirdCategory.length; int3++) {
								var tc = thirdCategory[int3];
								var tcName = tc.third_category_name;
								var tcName2 = tcName;
								if (tcName.length > 9) {
									tcName = tcName.substring(0, 9);
								}
								var tcId = tc.third_category_id;
								thirdUl += "<li  title='" + tcName2
										+ "'><a href='javascript:void()' onclick='storeClick.click(" + tcId + ",3,"
										+ intTc + ")'>" + tcName + "</a></li>";
								intTc += 1;
							}
							thirdUl += "</ul>";
						}
						var scName = sc.second_category_name;
						var scName2 = scName;
						if (scName.length > 9) {
							scName = scName.substring(0, 9);
						}
						var scId = sc.second_category_id;
						secondUl += "<li " + secondCss + " title='" + scName2
								+ "'><a href='javascript:void()' onclick='storeClick.click(" + scId + ",2," + intSc
								+ ")'>" + scName + "</a></li>" + thirdUl;
						intSc += 1;
					}
					secondUl += "</ul>";
				}
				var name = fc.first_category_name;
				var fcName = name;
				if (name.length > 9) {
					name = name.substring(0, 9);
				}
				var id = fc.first_category_id;
				content += "<li " + firstCss + " title='" + fcName + "'><a href='javascript:void()'"
						+ " onclick='storeClick.click(" + id + ",1," + intFc + ")'>" + name + "</a></li>" + secondUl;
				intFc += 1;
			}
		} else {
			content = "<li>暂无数据</li>";
		}
		store.append(content);
	},
	showOrHide : function(int, type) {
		var temp = "";
		switch (type) {
		case 1:
			$("ul[id^='second']").slideUp();
			$("ul[id^='second']").prev().removeClass("jian").addClass("jia");

			$("ul[id^='third']").slideUp();
			$("ul[id^='third']").prev().removeClass("jian").addClass("jia");
			temp = $("#second" + int);// 一级分类
			break;
		case 2:
			$("ul[id^='third']").slideUp();
			$("ul[id^='third']").prev().removeClass("jian").addClass("jia");

			name = "";
			temp = $("#third" + int);
			break;
		}
		if (type != 3) {
			var tof = temp.is(":hidden");
			if (false == tof) {
				temp.prev().removeClass("jian").addClass("jia");
				temp.slideUp();
			} else {
				temp.prev().removeClass("jia").addClass("jian");
				temp.slideDown();
			}
		}
	}
};
var storeClick = {
	click : function(id, type, int) {
		categoryClickProjectSearch(id, type);
		storeOnload.showOrHide(int, type);
	}
};
var leftHideOrShow = {
	clickFn : function() {
		$(".sz_nav_left_top").click(function() {
			var thisTemp = $(this);
			var temp = $(this).next().is(":hidden");
			var temp2 = $(this).find("h1");
			var temp3 = $(this).next();
			if (false == temp) {
				temp2.removeClass("jian").addClass("jia");
				temp3.slideUp("normal", function() {
					thisTemp.addClass("store1");
				});
			} else {
				temp2.removeClass("jia").addClass("jian");
				$(this).removeClass("store1");
				temp3.slideDown();
			}
		});
	}
};
var publicOnload = {
	onload : function() {
		storeOnload.firstCategory();
		leftHideOrShow.clickFn();
		$("#store").find("a").click(function() {
			$("#store").find("*").removeClass("sz_nav_left_xz");
			$(this).parent().addClass("sz_nav_left_xz");
		});
	}
};

// *********************************** 顶部_类别展示
var showCategory = {
	allCategory : "",
	secondCategory : "",
	thirdCategory : "",
	getFC : function() {
		$.ajax({
			async : false,
			dataType : "json",
			type : "POST",
			url : "/app/category!getAllCategory",
			success : function(data) {
				backUrl.addCookie(data.state);
				if ('success' == data.state) {
					showCategory.allCategory = data.msg;
					showCategory.createFC(data.msg);
				} else if ('error' == data.state) {
					errorAlert(data.msg);
				}
			}
		});
	},
	createFC : function(data) {
		var fc = $("#firstCategory");
		fc.empty();
		$("#secondCategory").empty();
		$("#thirdCategory").empty();
		var content = "";
		if (null != data) {
			$.each(data, function(i, v) {
				content += "<li><a onclick='showCategory.fcClick(" + v.first_category_id + "," + i
						+ ")' href='javascript:void()'>" + v.first_category_name + "</a></li>";
			});
		} else {
			content = "<li>暂无数据</li>";
		}
		fc.append(content);
	},
	fcClick : function(id, index) {
		var fc = showCategory.allCategory[index];
		var xzFc = $("#fcCategoryId");
		var xzFcId = xzFc.attr("fcCategoryId");
		if (xzFcId != id) {
			xzFc.html(fc.first_category_name + "<img src='/img/c.jpg'/>").attr("fcCategoryId", fc.first_category_id);//
			$("#scCategoryId").attr("scCategoryId", 0).text("");
			$("#tcCategoryId").attr("tcCategoryId", 0).text("");

			showCategory.secondCategory = fc.secondCategories;// 二级
			var sc = $("#secondCategory");
			sc.empty();
			$("#secondCategory").empty();
			$("#thirdCategory").empty();
			var content = "";
			var data = showCategory.secondCategory;
			if (null != data) {
				$.each(data, function(i, v) {
					content += "<li><a onclick='showCategory.scClick(" + v.second_category_id + "," + i
							+ ")' href='javascript:void()'>" + v.second_category_name + "</a></li>";
				});
			} else {
				content = "<li>暂无数据</li>";
			}
			sc.append(content);
			this.xzFn();
		}
	},
	scClick : function(id, index) {
		var sc = showCategory.secondCategory[index];
		var xzSc = $("#scCategoryId");
		var xzScId = xzSc.attr("scCategoryId");
		if (xzScId != id) {
			xzSc.html(sc.second_category_name + "<img src='/img/c.jpg'/>").attr("scCategoryId", sc.second_category_id);
			$("#tcCategoryId").attr("tcCategoryId", 0).text("");

			showCategory.thirdCategory = sc.thirdCategories;// 三级
			var tc = $("#thirdCategory");
			tc.empty();
			var content = "";
			var data = showCategory.thirdCategory;
			if (null != data) {
				$.each(data, function(i, v) {
					content += "<li><a onclick='showCategory.tcClick(" + v.third_category_id + "," + i
							+ ")' href='javascript:void()'>" + v.third_category_name + "</a></li>";
				});
			} else {
				content = "<li>暂无数据</li>";
			}
			tc.append(content);
			this.xzFn();
		}
	},
	tcClick : function(id, index) {
		var tc = showCategory.thirdCategory[index];
		var xzTc = $("#tcCategoryId");
		var xzTcId = xzTc.attr("tcCategoryId");
		if (xzTcId != id) {
			xzTc.html(tc.third_category_name + "<img src='/img/c.jpg'/>").attr("tcCategoryId", tc.third_category_id);
		}
	},
	xzFn : function() {
		$(".sz_entry_top").find("a").bind("click", function() {
			$(this).parent().addClass("sz_entry_top_1_zx").siblings().removeClass("sz_entry_top_1_zx");
		});
	},
	qcxzFn : function() {
		$("#xzCategory").children("li").click(function() {
			var id = $(this).attr("id");
			$("#" + id).attr(id, 0).text("");
			var temp = null;
			switch (id) {
			case "fcCategoryId":
				temp = $("#firstCategory");
				$("#secondCategory").text("");
				$("#thirdCategory").text("");
				$("#scCategoryId").attr("scCategoryId", 0).text("");
				$("#tcCategoryId").attr("tcCategoryId", 0).text("");
				break;
			case "scCategoryId":
				temp = $("#secondCategory");
				$("#thirdCategory").text("");
				$("#tcCategoryId").attr("tcCategoryId", 0).text("");
				break;
			case "tcCategoryId":
				temp = $("#thirdCategory");
				break;
			}
			temp.children("li").removeClass("sz_entry_top_1_zx");
		});
	},
	onload : function() {
		this.getFC();
		this.xzFn();
		this.qcxzFn();

		var yfc = $("#yFristCategroyName").val();
		var fc = $("#firstCategory").find("a");
		fc.each(function() {
			var tfc = $(this);
			var vfc = tfc.text();
			if (vfc == yfc) {
				tfc.click();
			}
		});
		var ysc = $("#ySecondCategroyName").val();
		var sc = $("#secondCategory").find("a");
		sc.each(function() {
			var tsc = $(this);
			var vsc = tsc.text();
			if (vsc == ysc) {
				tsc.click();
			}
		});
		var ytc = $("#yThirdCategroyName").val();
		var tc = $("#thirdCategory").find("a");
		tc.each(function() {
			var ttc = $(this);
			var vtc = ttc.text();
			if (vtc == ytc) {
				ttc.click();
			}
		});
	}
};
// ********************************************************批注
/**
 * 批注
 */
var projectNotation = {
	show : function(pid) {
		art.dialog.open("/app/comment!jumpListComment?pid=" + pid, {
			lock : true,
			title : "批注",
			width : "720px",
			height : "500px",
			id : "projectNotation"
		});
	}
};
